package org.vectrics.recruiter.job.event;

import java.util.Iterator;
import java.util.Locale;
import org.apache.ecs.html.Font;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;
import org.vectrics.mail.EmailHtmlBase;
import org.vectrics.mail.EmailTable;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.job.JobCandidate;
import org.vectrics.recruiter.job.JobCandidateStatus;

public class JobCandidateStatusHistoryEmailTable extends EmailTable {

	public JobCandidateStatusHistoryEmailTable(Locale locale, JobCandidate jobCandidate) {
		super(locale);
		this.setWidth(600);
		
		
		Row row = this.addRow();

		Cell cell = row.addCell();
		Font font = EmailHtmlBase.createBoldSmallFont();
		font.addElement(this.getPhrase("prompt.job.candidate.status"));
		cell.addElement(font);
		
		cell = row.addCell();
		font = EmailHtmlBase.createBoldSmallFont();
		font.addElement(this.getPhrase("prompt.date.start"));
		cell.addElement(font);

		cell = row.addCell();
		font = EmailHtmlBase.createBoldSmallFont();
		font.addElement(this.getPhrase("prompt.date.end"));
		cell.addElement(font);
		
		cell = row.addCell();
		font = EmailHtmlBase.createBoldSmallFont();
		font.addElement(this.getPhrase("prompt.person.who.changed"));
		cell.addElement(font);
		
		Iterator iter = jobCandidate.getStatusList().iterator();
		while (iter.hasNext()) {
			JobCandidateStatus jobCandidateStatus = (JobCandidateStatus)iter.next();
			row = this.addRow();

			cell = row.addCell();
			font = EmailHtmlBase.createSmallFont();
			font.addElement(jobCandidateStatus.getStatusType().getDescription() + "<br><i>" + 
					jobCandidateStatus.getJobCandidateStatusReasonType().getName()
					+ "</i>");
			cell.addElement(font);
			
			cell = row.addCell();
			font = EmailHtmlBase.createSmallFont();
			font.addElement(CoreServiceLocator.getDateFormat().getDateFormatRoundToDay(this.getLocale()).format(jobCandidateStatus.getDateStart()));
			cell.addElement(font);

			cell = row.addCell();
			font = EmailHtmlBase.createSmallFont();
			if (jobCandidateStatus.getDateEnd() != null)
				font.addElement(CoreServiceLocator.getDateFormat().getDateFormatRoundToDay(this.getLocale()).format(jobCandidateStatus.getDateEnd()));
			cell.addElement(font);
			
			cell = row.addCell();
			font = EmailHtmlBase.createSmallFont();
			font.addElement(jobCandidateStatus.getPerson().getName());
			cell.addElement(font);
			
		}
	}

}
